package org.yn.auth.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yn.auth.annotation.PermissionAnnotation;
import org.yn.auth.domain.Permission;
import org.yn.auth.query.PermissionQuery;
import org.yn.auth.service.IPermissionService;
import org.yn.base.util.AjaxResult;
import org.yn.base.util.PageInfo;

import java.util.List;
@PermissionAnnotation(name="权限管理",descs = "权限管理")
@RestController
@RequestMapping("/permission")
@Api("权限管理接口")
public class PermissionController {
        @Autowired
        private IPermissionService permissionService;
    /**
     * 分页查询
     */
    @PermissionAnnotation(name="权限的分页查询",descs = "权限的分页查询")
    @PutMapping
    @ApiOperation("权限的分页查询")
  public AjaxResult queryPage(@RequestBody PermissionQuery permissionQuery){


        try {
            PageInfo<Permission> pageInfo = permissionService.queryPage(permissionQuery);
            return AjaxResult.success(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 删除全部
     *
     */
    @PermissionAnnotation(name="权限的删除全部",descs = "权限的删除全部")
    @DeleteMapping()
    @ApiOperation("删除全部")
    public AjaxResult deleteAll(){
        permissionService.deleteAll();
        return AjaxResult.success("cg");
    }

    /**
     * 获取权限树
     */
    @PermissionAnnotation(name="获取权限树",descs = "获取权限树")
    @GetMapping()
    @ApiOperation("获取权限树")
    public AjaxResult queryPermission(){
        try {
            List<Permission> permissionList = permissionService.queryPermission();
            return AjaxResult.success(permissionList);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }



}
